<template>
  <div v-if="isAddConversationItemVisible">
    <el-dialog title="添加会话" :visible.sync="isAddConversationItemVisible" width="500px" :before-close="handleClose">
      <el-input type="text" v-model="userID" autocomplete="off" placeholder="请输入 userID"></el-input>
      <div style="text-align:right;padding-top:20px">
        <el-button type="primary" @click="handleClick">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex';

export default {
  data() {
    return {
      userID: ''
    }
  },
  computed: {
    ...mapState({
      isAddConversationItemVisible: state => state.conversation.isAddConversationItemVisible
    })
  },
  methods: {
    handleClose() {
      this.$store.commit('toggleIsAddConversationItemVisible',false);
    },
    handleClick() {
      if (this.userID !== '@TIM#SYSTEM' && this.userID !== '') {
        this.$store.dispatch('checkoutConversation', `C2C${this.userID}`)
        .then(() => {
          this.$store.commit('toggleIsAddConversationItemVisible',false);
        }).catch(() => {
          this.$store.commit('showMessage', { message: '没有找到该用户', type: 'warning' });
        });
      } else {
        this.$store.commit('showMessage', { message: '没有找到该用户', type: 'warning' });
      }
      this.userID = '';
    }
  }
}
</script>

<style scoped>

</style>